#include <Arduino.h>
#include "SR04.h"
SR04::SR04(int TP, int EP)
{  //鍒濆鍖栧紩鑴�
   pinMode(TP,OUTPUT);
   pinMode(EP,INPUT);  //echoPin PWM鑴夊啿璋冨埗淇″彿
   Trig_pin=TP;
   Echo_pin=EP;
}
 
float SR04::GetDistance()
{
	digitalWrite(Trig_pin, LOW); 
	delayMicroseconds(2);   //2寰
	digitalWrite(Trig_pin, HIGH); 
	delayMicroseconds(10);  //10us
	digitalWrite(Trig_pin, LOW); 
	float distance = pulseIn(Echo_pin, HIGH) / 58.00;
	return distance;
}
